window.onload = function(){
	var aInput = document.getElementsByTagName('input');
	var oUserName = document.getElementById('userName');
	var oNikiName  = document.getElementById('nikiName');
	var oEmail = document.getElementById('email');
	var oPsw = document.getElementById('psw');
	var oPswConfirm = document.getElementById('pswConfirm');
	var ouserName_Msg = document.getElementById('userName_Msg');
	var ouserName_status = document.getElementById('userName_status');
	var oNikiName_Msg = document.getElementById('nikiName_Msg');
	var oNikiName_status = document.getElementById('nikiName_status');
	var oEmail_Msg = document.getElementById('email_Msg');
	var oEmail_status = document.getElementById('email_status');
	var oPsw_Msg = document.getElementById('psw_Msg');
	var oPsw_status = document.getElementById('psw_status');

	function getLength(str){
		return str.replace(/[^\x00-xff]/g, "xx").length;
	}

	// 用户名

	oUserName.onfocus = function(){
		ouserName_status.innerHTML = '<img src="images/emblem.png"></img>'
		ouserName_Msg.innerHTML = '5-25个字符，一个汉字包含两个字符。'
		ouserName_Msg.style.color = 'orange';
	}

	oUserName.onblur = function(){
		// 含有非法字符
		var reg = /[^\w\u4e00-\u9fa5]/g;
		if(reg.test(this.value)){
			ouserName_status.innerHTML = '<img src="images/error.png"></img>'
			ouserName_Msg.innerHTML = '含有非法字符！'
			ouserName_Msg.style.color = 'red';
		}
		// 不能为空
		else if(this.value == ''){
			ouserName_status.innerHTML = '<img src="images/error.png"></img>'
			ouserName_Msg.innerHTML = '不能为空！'
			ouserName_Msg.style.color = 'red';
		}
		// 长度超过25个字符
		else if(getLength(this.value)>25){
			ouserName_status.innerHTML = '<img src="images/error.png"></img>'
			ouserName_Msg.innerHTML = '长度超过25个字符！'
			ouserName_Msg.style.color = 'red';
		}
		// 长度少于6个字符
		else if(getLength(this.value)<6){
			ouserName_status.innerHTML = '<img src="images/error.png"></img>'
			ouserName_Msg.innerHTML = '长度少于6个字符!'
			ouserName_Msg.style.color = 'red';
		}
		// OK
		else{
			ouserName_status.innerHTML = '<img src="images/ok.png"></img>'
			ouserName_Msg.innerHTML = 'OK!'
			ouserName_Msg.style.color = 'green';
		}
	}

	// nikiName
	oNikiName.onfocus = function(){
		oNikiName_status.innerHTML = '<img src="images/emblem.png"></img>'
		oNikiName_Msg.innerHTML = '5-25个字符，一个汉字包含两个字符。'
		oNikiName_Msg.style.color = 'orange';
	}

	oNikiName.onblur = function(){
		// 含有非法字符
		var reg = /[^\w\u4e00-\u9fa5]/g;
		if(reg.test(this.value)){
			oNikiName_status.innerHTML = '<img src="images/error.png"></img>'
			oNikiName_Msg.innerHTML = '含有非法字符！'
			oNikiName_Msg.style.color = 'red';
		}
		// 不能为空
		else if(this.value == ''){
			oNikiName_status.innerHTML = '<img src="images/error.png"></img>'
			oNikiName_Msg.innerHTML = '不能为空！'
			oNikiName_Msg.style.color = 'red';
		}
		// 长度超过25个字符
		else if(getLength(this.value)>25){
			oNikiName_status.innerHTML = '<img src="images/error.png"></img>'
			oNikiName_Msg.innerHTML = '长度超过25个字符！'
			oNikiName_Msg.style.color = 'red';
		}
		// 长度少于6个字符
		else if(getLength(this.value)<6){
			oNikiName_status.innerHTML = '<img src="images/error.png"></img>'
			oNikiName_Msg.innerHTML = '长度少于6个字符!'
			oNikiName_Msg.style.color = 'red';
		}
		// OK
		else{
			oNikiName_status.innerHTML = '<img src="images/ok.png"></img>'
			oNikiName_Msg.innerHTML = 'OK!'
			oNikiName_Msg.style.color = 'green';
		}
	}

	//Email
	oEmail.onfocus = function(){
		oEmail_status.innerHTML = '<img src="images/emblem.png"></img>'
		oEmail_Msg.innerHTML = '请输入正确的邮箱格式！'
		oEmail_Msg.style.color = 'orange';
	}

	oEmail.onblur = function(){
		// OK
		var reg = /^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g;
		if(reg.test(this.value)){
			oEmail_status.innerHTML = '<img src="images/ok.png"></img>'
			oEmail_Msg.innerHTML = 'OK!'
			oEmail_Msg.style.color = 'green';
		}
		// 不能为空
		else if(this.value == ''){
			oEmail_status.innerHTML = '<img src="images/error.png"></img>'
			oEmail_Msg.innerHTML = '不能为空！'
			oEmail_Msg.style.color = 'red';
		}
		// 邮箱格式不正确
		else{
			oEmail_status.innerHTML = '<img src="images/error.png"></img>'
			oEmail_Msg.innerHTML = '输入的邮箱格式不正确！'
			oEmail_Msg.style.color = 'red';
		}
	}

	//password
	oPsw.onfocus = function(){
		oPsw_status.innerHTML = '<img src="images/emblem.png"></img>'
		oPsw_Msg.innerHTML = '密码由数字和字符组成，6~16位！'
		oPsw_Msg.style.color = 'orange';
	}

	oPsw.onblur = function(){
		// OK
		var reg = /^[a-zA-Z0-9]{6,16}$/; 
		if(reg.test(this.value)){
			oPsw_status.innerHTML = '<img src="images/ok.png"></img>'
			oPsw_Msg.innerHTML = 'OK!'
			oPsw_Msg.style.color = 'green';
		}
		// 不能为空
		else if(this.value == ''){
			oPsw_status.innerHTML = '<img src="images/error.png"></img>'
			oPsw_Msg.innerHTML = '不能为空！'
			oPsw_Msg.style.color = 'red';
		}
		// 邮箱格式不正确
		else{
			oPsw_status.innerHTML = '<img src="images/error.png"></img>'
			oPsw_Msg.innerHTML = '输入的密码格式不正确！'
			oPsw_Msg.style.color = 'red';
		}
	}
}